﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.ObjectBuilder;
using NetDon.OA.Data.CollectionClasses;
using NetDon.OA.Data.EntityClasses;
using NetDon.OA.Data.HelperClasses;
using NetDon.OA.Interface;
using NetDon.OA.Interface.Common;
using NetDon.Utilities;
using NetDon.WebControls;

namespace NetDon.OA.Portal.Admin
{
    [Navigation("系统管理", "交货单信息维护")]
    public partial class DeliveryOrderCodeManagement : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateRoutes();
            } 
          
        }

        protected void gridItem_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var btnModify = e.Row.FindControl("btnModify") as ImageButton;
                if (btnModify != null)
                {
                    btnModify.OnClientClick = string.Format("OpenEditPage('{0}');return false;",
                                                              DataBinder.Eval(e.Row.DataItem, "Id"));
                }
            }
        }

        protected void gridItem_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "DeleteItem":
                    OnRemoveCurrency(new EventArgs<Guid>(e.CommandArgument.ToString().ToGuid()));
                    break;
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            PopulateRoutes();
        }

        #region Implementation of ICurrencyView

        public void PopulateRoutes()
        {
            var orderDeliveryCodeConfigs = new DeliveryOrderCodeConfigCollection();
            orderDeliveryCodeConfigs.GetMulti(null);
            this.gridCurrency.DataSource = orderDeliveryCodeConfigs;
            this.gridCurrency.DataBind();
        }


        protected virtual void OnRemoveCurrency(EventArgs<Guid> e)
        {
            new DeliveryOrderCodeConfigEntity(e.Data).Delete();
            PopulateRoutes();
        }

        #endregion



    }
}